package Q1;

import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

/**
 * Hibernate 配置
 *
 * @author chisheng
 * @since 2021-10-25
 */
public class HibernateConfig {

    /**
     * Hibernate 会话工厂
     */
    private static final SessionFactory FACTORY;

    static {
        /* Hibernate 4.3+ 会话工厂的静态初始化 */
        StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
        FACTORY = new MetadataSources(registry).getMetadataBuilder().build().buildSessionFactory();
    }

    /**
     * 返回一个会话工厂实例
     *
     * @return Hibernate 会话工厂实例
     */
    public static SessionFactory getSessionFactory() {
        return FACTORY;
    }

}
